home *** CD-ROM | disk | FTP | other *** search
/ Master Visual Basic 3 / Master Visual Basic 3 (SAMS Publishing) (1994).ISO / mvprog / original / ch08 / sequen.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-03-30  |  5.2 KB  |  176 lines

  1. VERSION 2.00
  2. Begin Form frmSequen 
  3.    Caption         =   "The Sequen Program"
  4.    ClientHeight    =   5940
  5.    ClientLeft      =   1110
  6.    ClientTop       =   735
  7.    ClientWidth     =   7350
  8.    Height          =   6345
  9.    Icon            =   SEQUEN.FRX:0000
  10.    Left            =   1050
  11.    LinkTopic       =   "Form1"
  12.    Picture         =   SEQUEN.FRX:0302
  13.    ScaleHeight     =   5940
  14.    ScaleWidth      =   7350
  15.    Top             =   390
  16.    Width           =   7470
  17.    Begin CheckBox chkWriteProtect 
  18.       BackColor       =   &H000000FF&
  19.       Caption         =   "Check1"
  20.       Height          =   195
  21.       Left            =   5040
  22.       TabIndex        =   5
  23.       Top             =   4080
  24.       Value           =   1  'Checked
  25.       Width           =   255
  26.    End
  27.    Begin CommonDialog CMDialog1 
  28.       CancelError     =   -1  'True
  29.       Left            =   5640
  30.       Top             =   360
  31.    End
  32.    Begin CommandButton cmdNew 
  33.       Caption         =   "&New..."
  34.       Height          =   495
  35.       Left            =   360
  36.       TabIndex        =   2
  37.       Top             =   2520
  38.       Width           =   1215
  39.    End
  40.    Begin CommandButton cmdOpen 
  41.       Caption         =   "&Open..."
  42.       Height          =   495
  43.       Left            =   360
  44.       TabIndex        =   3
  45.       Top             =   1920
  46.       Width           =   1215
  47.    End
  48.    Begin CommandButton cmdWrite 
  49.       Caption         =   "&Write"
  50.       Enabled         =   0   'False
  51.       Height          =   975
  52.       Left            =   5640
  53.       TabIndex        =   4
  54.       Top             =   1800
  55.       Width           =   1215
  56.    End
  57.    Begin TextBox txtFile 
  58.       Height          =   1335
  59.       Left            =   360
  60.       MultiLine       =   -1  'True
  61.       ScrollBars      =   3  'Both
  62.       TabIndex        =   1
  63.       Top             =   4560
  64.       Width           =   6735
  65.    End
  66.    Begin CommandButton cmdExit 
  67.       Caption         =   "E&xit"
  68.       Height          =   495
  69.       Left            =   360
  70.       TabIndex        =   0
  71.       Top             =   3120
  72.       Width           =   1215
  73.    End
  74. Option Explicit
  75. Const IDNO = 7
  76. Sub cmdExit_Click ()
  77.    End
  78. End Sub
  79. Sub cmdNew_Click ()
  80.     Dim Answer
  81.     Dim FileNum
  82.     Dim OriginalFileName
  83.     ' Set an error trap to detect if
  84.     ' the user clicked the Cancel button
  85.     ' of the Save As dialog box.
  86.     On Error GoTo SaveAsError
  87.     ' Fill the items of the File Type list box of
  88.     ' the Save As dialog box.
  89.     CMDialog1.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt"
  90.     ' Set the default File Type to *.txt
  91.     CMDialog1.FilterIndex = 1
  92.    ' Display the Save As dialog box
  93.    OriginalFileName = CMDialog1.Filename
  94.    CMDialog1.Action = 2
  95.    On Error GoTo 0
  96.    If Dir(CMDialog1.Filename) <> "" Then
  97.       
  98.       Answer = MsgBox(CMDialog1.Filename + Chr$(13) + "File exists already. Overwrite it?", 4)
  99.       
  100.       If Answer = IDNO Then
  101.          CMDialog1.Filename = OriginalFileName
  102.          Exit Sub
  103.       End If
  104.    End If
  105.     ' Get a free file number
  106.     FileNum = FreeFile
  107.     Open CMDialog1.Filename For Output As FileNum
  108.     Write #FileNum, "SEQUEN HEADER", ""
  109.     Close FileNum
  110.     frmSequen.Caption = "SEQUEN - " + CMDialog1.Filetitle
  111.     txtFile.Text = ""
  112.     cmdWrite.Enabled = True
  113.    ' Exit the procedure
  114.    Exit Sub
  115. SaveAsError:
  116.    Exit Sub
  117. End Sub
  118. Sub cmdOpen_Click ()
  119.     Dim Header
  120.     Dim FileNum
  121.     Dim ReadData
  122.     Dim OriginalFileName
  123.     ' Set an error trap to detect if
  124.     ' the user clicked the Cancel button
  125.     ' of the Open dialog box.
  126.     On Error GoTo OpenError
  127.     ' Fill the items of the File Type list box of
  128.     ' the Open dialog box.
  129.     CMDialog1.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt"
  130.     ' Set the default File Type to *.txt
  131.     CMDialog1.FilterIndex = 1
  132.    ' Display the Open dialog box
  133.    OriginalFileName = CMDialog1.Filename
  134.    CMDialog1.Action = 1
  135.    On Error GoTo 0
  136.    If Dir(CMDialog1.Filename) = "" Then
  137.       
  138.       MsgBox CMDialog1.Filename + Chr$(13) + "File does not exist.", 0
  139.       
  140.       CMDialog1.Filename = OriginalFileName
  141.       Exit Sub
  142.    End If
  143.     FileNum = FreeFile
  144.     Open CMDialog1.Filename For Input As FileNum
  145.     If FileLen(CMDialog1.Filename) > 0 Then
  146.        Input #FileNum, Header
  147.     End If
  148.     If Header <> "SEQUEN HEADER" Then
  149.        MsgBox CMDialog1.Filename + " is not a SEQUEN file!", 48
  150.        CMDialog1.Filename = OriginalFileName
  151.     Else
  152.        frmSequen.Caption = "SEQUEN - " + CMDialog1.Filetitle
  153.        cmdWrite.Enabled = True
  154.        Input #FileNum, ReadData
  155.        txtFile.Text = ReadData
  156.     End If
  157.     Close FileNum
  158.    ' Exit the procedure
  159.    Exit Sub
  160. OpenError:
  161.    Exit Sub
  162. End Sub
  163. Sub cmdWrite_Click ()
  164.     Dim FileNum
  165.     If chkWriteProtect.Value = 0 Then
  166.        
  167.        MsgBox "Place an X inside the write protect check box!"
  168.        Exit Sub
  169.     End If
  170.     FileNum = FreeFile
  171.     Open CMDialog1.Filename For Output As FileNum
  172.     Write #FileNum, "SEQUEN HEADER", txtFile.Text
  173.       
  174.     Close FileNum
  175. End Sub
  176.